const domainWhite = [
    'local-activity.changyou.com',
    'dev-activity.changyou.com',
    'test-activity.changyou.com'
];
const isOK = domainWhite.includes(location.host);


if(isOK) {
  const cyLog = {
    send(data = {}) {
      let image = new Image(1, 1);
      image.onload = function () {
          image = null;
      };
      data.env = location.host.split('-')[0]    // 当前环境
      image.src = `/logApi/cy.gif?${$.param(data)}`;
    }
  }

  
  $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
    options.complete = function(request, status) {
      if(status === 'success' && request.responseText) {
        var code = Number(JSON.parse(request.responseText).code);
        if(code !== 10000) {
          console.log(options)
          // console.log(originalOptions)
          // console.log(jqXHR)

          cyLog.send({
            title: 'code error',
            code: code,
            url: options.url,
            headers: JSON.stringify(options.headers),
            responseText: request.responseText
          })

        }
      } else {
        cyLog.send({
          title: 'http error',
          url: options.url,
          headers: JSON.stringify(options.headers),
          responseText: request.responseText
        })
      }
    }
  })

  // window.onerror = function (message, source, lineno, colno, error) {
  //   cyLog.send({
  //       activity: ja.activity,
  //       message: [
  //           'title：' + 'window error',
  //           'errorMessage：' + message + '----in：' + source + '：' + lineno + '：' + colno
  //       ].join('\n')
  //   })
  // }

}